import { DataSource  } from 'typeorm'
import {User} from '../entity/User.js'

const {MYSQL_HOST, MYSQL_PORT, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE} = process.env

export const mysqlDataSource = new DataSource({
	'type': 'mysql',
	'host': MYSQL_HOST,
	'port': Number(MYSQL_PORT),
	'username': MYSQL_USERNAME,
	'password': MYSQL_PASSWORD,
	'database': MYSQL_DATABASE,
	'entities': [User],
	// 'synchronize': true,
	'logging': true,
})

export function connectMysqlDataSource(): Promise<DataSource> {
	return mysqlDataSource.initialize()
}

